﻿using System.Data.Entity;

using System.Collections.Generic;

using System.Linq;
using SIG.Model;
using SIG.Data.UnitOfWork;
using SIG.Infrastructure.Cache;
using SIG.Data;
using System;

namespace SIG.Repository
{
    public class ProductRepository : Repository<Product>, IProductRepository
    {
        IMainBCUnitOfWork _unitOfWork;
        private ICacheService _cacheService;
        public ProductRepository(IMainBCUnitOfWork unitOfWork, ICacheService cacheService) : base(unitOfWork) {
            if (unitOfWork == (IMainBCUnitOfWork)null)
                throw new ArgumentNullException("unitOfWork");
            if (cacheService == (ICacheService)null)
                throw new ArgumentNullException("cacheService");
            this._unitOfWork = unitOfWork;
            this._cacheService = cacheService;
        }




       // public IEnumerable<Product> GetAllWithCategory()
       // {
       //     return this._dbset.Include(p => p.Categories).ToList();
       // }

       // public Product GetWithCategoryById(int id)
       // {
       //     return this._dbset.Include(p=>p.Categories).SingleOrDefault(p=>p.Id == id);
       // }

       // public override Product GetById(object id)
       // {
       //     return _dbset.Include(p=>p.Categories).Include(p=>p.ProductPhotos).SingleOrDefault(p => p.Id == (int)id);
       // }

       // public int SearchProductsCount()
       // {


       //     var products = this.GetAll().AsQueryable();

       //     var result = products.Count();

       //     return result;
       // }

       //public  IList<Product> SearchProducts(int pageIndex, int pageSize)
       // {
       //     var products = this._dbset.Include(p => p.Categories).Include(p=>p.ProductPhotos).AsQueryable();

       //     var result = products
       //         .OrderByDescending(l => l.CreatedDate)
       //         .Skip(pageIndex * pageSize).Take(pageSize).ToList();

       //     return products.ToList();
            
       // }

       //public IList<Product> GetActiveProducts(int pageIndex, int pageSize,int catId)
       //{
       //    var products = this._dbset.Include(p => p.Categories).Include(p => p.ProductPhotos).Where(p => p.Active).AsQueryable();

       //    if (catId > 0)
       //    {              
       //        products = products.Where(p => p.Categories.Any(c=>c.Id==catId || c.ParentId == catId));
       //    }

       //    var result = products
       //        //.OrderByDescending(l => l.CreatedDate)
       //        .Skip(pageIndex * pageSize).Take(pageSize).ToList();

       //    return result;
       //}

       //public int ActiveProductsCount(int catId)
       // {
       //     var products = this._dbset.Include(p => p.Categories).Where(p => p.Active).AsQueryable();

       //     if (catId > 0)
       //     {                
       //         products = products.Where(p => p.Categories.Any(c => c.Id == catId || c.ParentId == catId));
       //     }

       //     var result = products.Count();

       //     return result;
       // }

       
    }
}
